import Vue from 'vue'
import App from './App.vue'
import router from "@/router";
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/css/font.css'
import VCharts from 'v-charts'
import  Cookies from 'vue-cookies'
import dataV from '@jiaminghi/data-view'

Vue.use(dataV)
Vue.use(VCharts)
Vue.use(ElementUI)
var axios = require('axios')
axios.defaults.baseURL = 'http://localhost:8443/api'
Vue.prototype.$axios = axios
Vue.prototype.Cookies = Cookies;
Vue.config.productionTip = false
Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  to.matched.some((route) => {
    if (route.meta.need2Login) {
      if(route.meta.needAdmin){
        if (Cookies.get("userType")==='admin')
          next();
        else if(Cookies.isKey("userName") && Cookies.isKey("userType"))
          next('/classList')
        else
          next('/login')
      }
      else{
        if (Cookies.isKey("userName") && Cookies.isKey("userType"))
          next();
        else
          next('/login')
      }
    }


    else {
      next();
    }
  })
});


new Vue({
  router,
  render: h => h(App),
  components: { App },
  template: '<App/>'
}).$mount('#app')
